package org.dtrd.modules.shop.entity.po;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Getter;
import lombok.Setter;
import org.dtrd.modules.shop.entity.bean.ProductPushDetail;
import org.dtrd.modules.shop.entity.request.ProductPushRequest;

import java.util.Date;


/**
 * <p>
 * 商品推送表
 * </p>
 *
 * @author sun
 * @since 2022-09-03
 */
@Getter
@Setter
@TableName("dtrd_ent_shc_rd_product_push")
public class DtrdEntShcRdProductPush {

    @TableId(value = "data_id", type = IdType.AUTO)
    private Integer dataId;

    /**
     * 医生id
     */
    @TableField("doctor_id")
    private Integer doctorId;

    /**
     * 患者id
     */
    @TableField("patient_id")
    private Integer patientId;

    /**
     * 推送商品
     */
    @TableField("products")
    private String products;

    /**
     * 结算金额
     */
    @TableField("use_price")
    private String usePrice;

    /**
     * 下单二维码
     */
    @TableField("qrcode_url")
    private String qrcodeUrl;

    /**
     * 是否删除
     */
    @TableField("is_del")
    @TableLogic
    private Integer isDel;

    /**
     * 创建时间
     */
    @TableField("create_time")
    private Date createTime;

    public DtrdEntShcRdProductPush init() {
        isDel = 0;
        createTime = new Date();
        return this;
    }

    public DtrdEntShcRdProductPush parseFromDto(ProductPushDetail dto) {
        dataId = dto.getDataId();
        doctorId = dto.getDoctorId();
        patientId = dto.getPatientId();
        products = dto.getProducts();
        usePrice = dto.getUsePrice();
        qrcodeUrl = dto.getQrcodeUrl();
        return this;
    }

    public DtrdEntShcRdProductPush parseFromDto(ProductPushRequest dto) {
        doctorId = dto.getDoctorId();
        patientId = dto.getPatientId();
        products = JSONArray.toJSONString(dto.getProducts());
        usePrice = dto.getUsePrice();
        return this;
    }

}
